import { VuexModule, Module, Action, getModule } from 'vuex-module-decorators'
import { getSysUsers, updateSysUsers, deleteSysUsers } from '@/api/sys_user'
import store from '@/store'

export interface ISysUserState {
    
}

@Module({ dynamic: true, store, name: 'SysUser' })
class SysUser extends VuexModule implements ISysUserState {

    @Action
    public async getSysUsers(uId?: number) {
        return new Promise((r: any, j: any) => {
            let data = uId ? { StaffId: uId } : null
            getSysUsers(data).then((value: any) => {
                console.error("Users:", value)
                r(value.data)
            }).catch(ex => {
                console.error(ex);
                j([])
            })
        })
    }

    @Action
    public async updateSysUsers(data: any) {
        return new Promise((r: any, j: any) => {
            updateSysUsers(data).then((value: any) => {
                console.error("Users:", value)
                r(value.data)
            }).catch(ex => {
                console.error(ex);
                j([])
            })
        })
    }

    @Action
    public async deleteSysUsers(staffId: any) {
        return new Promise((r: any, j: any) => {
            deleteSysUsers({ StaffId: staffId }).then((value: any) => {
                console.error("Users:", value)
                r(value.data)
            }).catch(ex => {
                console.error(ex);
                j([])
            })
        })
    }

}

export const SysUserModule = getModule(SysUser)
